<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增楼号')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-building-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">楼号名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="name" placeholder="请输入楼号" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类型：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="type" value="楼号" readonly="true">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "building";

    $("#form-building-add").validate({
        rules: {
            onkeyup: false,
            name: {
                remote: {
                    url: prefix + "/checkNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "name": function () {
                            return $("input[name='name']").val();
                        },
                        "type": function () {
                            return $("input[name='type']").val();
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            }
        },
        messages: {
            "name": {
                remote: "楼号已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-building-add").serializeArray();
            $.operate.save(prefix + "/save", data);
        }
    }

</script>
</body>
</html>